import 'package:flutter/material.dart';
import 'package:flutter_shop/pages/details_page/details_bottom.dart';
import 'package:flutter_shop/pages/details_page/details_explain.dart';
import 'package:flutter_shop/pages/details_page/details_tabbar.dart';
import 'package:flutter_shop/pages/details_page/details_top_area.dart';
import 'package:flutter_shop/pages/details_page/details_web.dart';
import 'package:flutter_shop/provide/details_provide.dart';
import 'package:provide/provide.dart';

///商品详情页
class DetailsPage extends StatefulWidget {
  String goodsId;

  DetailsPage({Key key, this.goodsId}) : super(key: key);

  @override
  _detailsPageState createState() => _detailsPageState();
}

class _detailsPageState extends State<DetailsPage> {


  @override
  Widget build(BuildContext context) {

    getGoodDetailByIdData(context );
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text('商品详情'),
      ),
      body: Provide<DetailsInfoProvide>(
        builder: (context,child,details){
          if (details.detailsModel!=null) {
            return Stack(
              children: <Widget>[
                SingleChildScrollView(
                  child: Container(
                    margin: EdgeInsets.only(bottom: 20.0),
                    child: Column(
                      children: <Widget>[
                        DetailsTopArea(),
                        DetailsExplain(),
                        DetailsTabBar(),
                        DetailsWeb(),
                      ],
                    ),
                  ),
                ),
                Positioned(left: 0, bottom: 0, child: DetailsBottom())
              ],
            );
          } else {
            return Text('加载中...');
          }
        },
      ),
    );
  }

   getGoodDetailByIdData(BuildContext context )async{
    await  Provide.value<DetailsInfoProvide>(context).getGoodsInfo(widget.goodsId);
  }
}
